package org.jeecg.modules.engineering.service.impl;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.jeecg.common.util.StringUtils;
import org.jeecg.modules.engineering.entity.EquipEventInfo;
import org.jeecg.modules.engineering.mapper.EquipEventInfoMapper;
import org.jeecg.modules.engineering.service.IEquipEventInfoService;
import org.jeecg.modules.engineering.vo.EquipEventInfoSum;
import org.jeecg.modules.engineering.vo.EquipEventInfoExt;
import org.jeecg.modules.engineering.vo.EventProcessStatus;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @Description: 设备事件信息表
 * @Author: jeecg-boot
 * @Date:   2019-08-20
 * @Version: V1.0
 */
@Service
public class EquipEventInfoServiceImpl extends ServiceImpl<EquipEventInfoMapper, EquipEventInfo> implements IEquipEventInfoService {

    @Autowired
    private EquipEventInfoMapper equipEventInfoMapper;

    @Override
    public List<EquipEventInfoExt> findEventInfoByProject(String projectId, Integer minLevel, Integer maxLevel) {
        return equipEventInfoMapper.findEventInfoByProject(projectId,minLevel,maxLevel);
    }

    @Override
    public List<EquipEventInfoSum> findEventInfoSumByProject(String projectId, String levelList, Date startTime) {
        if (startTime == null){
            Calendar ca = Calendar.getInstance();
            ca.add(Calendar.DATE,-7);
            ca.set(Calendar.HOUR,0);
            ca.set(Calendar.MINUTE,0);
            ca.set(Calendar.SECOND,0);
            ca.set(Calendar.MILLISECOND,0);
            startTime = ca.getTime();
        }
        List<String> levelToList = null;
        if (StringUtils.isNotBlank(levelList)){
            levelToList = Arrays.asList(levelList.split(","));
        }
        return equipEventInfoMapper.findEventInfoSumByProject(projectId,levelToList,startTime);
    }

    @Override
    public List<EventProcessStatus> findUnProcessByProjectAndSystem(String projectId, String topSystem) {
        return equipEventInfoMapper.findUnProcessByProjectAndSystem(projectId,topSystem);
    }

    @Override
    public IPage<EquipEventInfo> selectSqlList(Page<EquipEventInfo> page, String eventId, String equipName, List<String> projectIds) {
        return page.setRecords(equipEventInfoMapper.selectSqlList(page,eventId,equipName,projectIds));
    }

    @Override
    public List<EquipEventInfo> selectSqlList(String eventId, String equipName, List<String> projectIds) {
        return equipEventInfoMapper.selectSqlList(eventId,equipName,projectIds);
    }

}
